package LuoGu.搜索.涂国旗;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main {
    static char [][] temp;
    static int m;
    static int [] w;
    static int [] b;
    static int [] r;
    public static void main(String[] args) throws IOException {
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        int n = (int) st.nval;
        st.nextToken();
        m = (int) st.nval;
        temp = new char[n][m];
        w = new int [m+1];
        b = new int [m+1];
        r = new int [m+1];
        for(int i=0;i<n;i++){
            st.nextToken();
            String tempp = st.sval;
            for(int j=0;j<m;j++){
                temp[i][j] = tempp.charAt(j);
            }
        }
        for(int i=0;i<n;i++){
            w[i+1] = w[i]+add('W',i);
            b[i+1] = b[i]+add('B',i);
            r[i+1] = r[i]+add('R',i);
        }
        int min = Integer.MAX_VALUE;
        for(int i=1;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                min = Math.min(min,w[i]+b[j]-b[i]+r[n]-r[j]);
            }
        }
        System.out.print(min);
    }

    public static int add(char c,int index){
        int ans = 0;
        for(int i=0;i<m;i++){
            if(temp[index][i]!=c) ans++;
        }
        return ans;
    }
}
